<template>
  <CDialog
    :visible="visible"
    title="选择电站预览"
    width="900px"
    @outerOpen="outerOpen"
    @cancel="handleCancel"
    top="5vh"
  >
    <TableSearch
      v-loading="loading"
      ref="tableSearch"
      :columns="columns"
      :tableData="tableData"
      @handleTableData="handleTableData"
      :pageNameDisplay="false"
    />
    <template slot="outerFooter">
      <el-button type="success" @click="handleClick">确定</el-button>
    </template>
  </CDialog>
</template>
<script>
import CDialog from '@/components/CDialog'
import TableSearch from '@/components/TableSearch'
import { nationsLinkStationPage } from '@/api/Insurance'
import formatter from '@/utils/format'
export default {
  name: 'PreviewStationDlgInsurance',
  components: { TableSearch, CDialog },
  props: {
    checkList: {
      type: Array,
      default: () => [],
    },
    visible: {
      type: Boolean,
      required: true,
    },
  },
  data() {
    return {
      loading: false,
      tableData: {},
      columns: [
        {
          label: '创建日期',
          prop: 'createTime',
          formatter,
        },
        {
          label: '所在地区',
          prop: 'provinceName',
          formatter: (row) => {
            return `${
              row.provinceName
                ? row.provinceName +
                  ' - ' +
                  row.cityName +
                  ' - ' +
                  row.districtName
                : ''
            }`
          },
        },
        {
          label: '充电站名',
          prop: 'stationName',
        },
        {
          label: '地址描述',
          prop: 'stationAddress',
        },
        {
          label: '停用状态',
          prop: 'unableCyclesStatusDesc',
        },
        {
          label: '包含充电口',
          prop: 'plug',
        },
      ],
    }
  },
  methods: {
    handleClick() {
      this.$emit('update:visible', false)
    },
    handleTableData(params) {
      let strIds = ''

      for (let i = 0; i < this.checkList.length; i++) {
        if (i !== this.checkList.length - 1) {
          strIds += `${this.checkList[i]},`
        } else {
          strIds += this.checkList[i]
        }
      }
      let qsParams = {
        ...params,
        ids: strIds,
      }
      this.loading = true
      nationsLinkStationPage(qsParams)
        .then((res) => {
          this.tableData = {
            list: res.list,
            totalCount: res.totalAmount,
          }
        })
        .catch((err) => {
          console.log(err)
        })
        .finally(() => {
          this.loading = false
        })
    },
    handleCancel() {
      this.$emit('update:visible', false)
    },
    outerOpen() {},
  },
}
</script>
<style lang="scss" scoped></style>
